extends VBoxContainer

signal button_pressed(index)
var count setget ,get_count

# 添加
func add(text:String,icon:String):
	var mbtn:Button = addNode(self,"Button")
	mbtn.text = text
	mbtn.icon = load(icon)
	mbtn.size_flags_vertical  = SIZE_EXPAND_FILL
	mbtn.connect("pressed",self,"btn_pressed",[mbtn.get_position_in_parent()])

# 移除
func remove(index:int) -> void:
	var nBtn:Button = get_child(index)
	remove_child(nBtn)

#清空
func clear() ->void:
	var children = get_children()
	for child in children:
		remove_child(child)
# 设置文本
func set_text(index:int,nValue:String) -> void:
	var nBtn:Button = get_child(index)
	nBtn.text = nValue

# 设置图标
func set_icon(index:int,nValue:String):
	var nBtn:Button = get_child(index)
	nBtn.icon = load(nValue)
	
# 返回按钮个数
func get_count():
	return get_child_count()

# 为节点动态添加子节点的函数封装
func addNode(pNode:Node,nodeType:String) -> Node:
	var childNode:Node = ClassDB.instance(nodeType) # ClassDB.instance(className)直接创建类名为className的实例
	pNode.add_child(childNode)
	childNode.owner = pNode
	return childNode

func btn_pressed(index:int):
	emit_signal("button_pressed",index)

